package k.b.s;

import java.io.InputStream;
import java.util.ArrayList;

import k.b.s.model.ChannelRowModel;
import k.b.s.model.ItemRowModel;

import android.app.Activity;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;

public class EntryKevin extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.entrykevin);
    }

    public void onClickGetContent(View v){
    	ArrayList<ChannelRowModel> CTB = OperationDB.getChannelTB(this);
    	SQLiteDatabase database = OperationDB.getWDB(this);
    	for(int i=0;i<CTB.size();i++){
    		InputStream in = HttpGetter.getContent(CTB.get(i).getChannel());
    		ArrayList<ItemRowModel> rowModels = ItemXmlHelper.getInstance().parseSax(in,CTB.get(i).getChannel());
    		OperationDB.addItem(rowModels,database, this );
    	}
    }
    public void onClickVDB(View v){
    	Intent intent = new Intent(this,DBTestView.class);
    	startActivity(intent);
    }
    public void onClickSetChannel(View v){
    	SQLiteDatabase database = OperationDB.getWDB(this);
    	InputStream in = HttpGetter.getContent("http://www3.nhk.or.jp/rss/news/cat0.xml");
    	ChannelRowModel rowModel = ChannelXmlHelper.getInstance().parseSax(in,"http://www3.nhk.or.jp/rss/news/cat0.xml");
    	OperationDB.addChannel(rowModel,database, this );
    	in = HttpGetter.getContent("http://sjz.jp/blog/feed/");
    	rowModel = ChannelXmlHelper.getInstance().parseSax(in,"http://sjz.jp/blog/feed/");
    	OperationDB.addChannel(rowModel,database,this );
//    	if(OperationDB.isNotFull(this)){
//			String http = "http://www3.nhk.orrss/news/cat0.xml";
//			SQLiteDatabase database = OperationDB.getWDB(this);
//	    	InputStream in = HttpGetter.getContent(http);
//	    	ChannelRowModel rowModel = ChannelXmlHelper.getInstance().parseSax(in,http);
//	    	OperationDB.addChannel(rowModel,database, this );
//		}else{
//			Toast.makeText(this, "追加できませんでした。", Toast.LENGTH_SHORT);
//		}
    }
    public void onClickBucho(View v){
    	Intent intent = new Intent(this,RssRegist.class);
    	startActivity(intent);
    }
}